package com.epam.tcs.dao.hibernate.impl;

import java.util.List;

import org.hibernate.Session;

import com.epam.tcs.dao.factory.LectureStatusDAO;
import com.epam.tcs.dao.hibernate.ConnectionFactory;
import com.epam.tcs.dao.hibernate.entities.LectureStatus;

;

public class LectureStatusDAOHibernateImpl extends
		ElementDAOHibernateImpl<LectureStatus> implements LectureStatusDAO {

	public LectureStatusDAOHibernateImpl(Class objType) {
		this.objType = objType;
	}

	@Override
	public LectureStatus getElement(long id) {
		Session session = ConnectionFactory.getOrInitSession();
		LectureStatus lectureStatus = (LectureStatus) session.load(objType, id);

		lectureStatus.getJournalLectureStatuses().get(0);

		session.close();
		return lectureStatus;
	}

	@Override
	public List<LectureStatus> getAllElements() {
		Session session = ConnectionFactory.getOrInitSession();
		List<LectureStatus> lectureStatuses = (List<LectureStatus>) session
				.createQuery("from " + objType.getName()).list();

		for (LectureStatus lectureStatus : lectureStatuses) {
			lectureStatus.getJournalLectureStatuses().get(0);
		}

		session.close();
		return lectureStatuses;
	}

}